package com.daoeping.action;

import java.util.List;

import com.daoeping.data.Cop_companyinfo;
import com.daoeping.data.Usr_projectexperience;
import com.daoeping.data.Usr_userbasicinfo;
import com.daoeping.data.Usr_workexperience;
import com.daoeping.service.Cop_companyinfoService;
import com.daoeping.service.Usr_projectexperienceService;
import com.daoeping.service.Usr_workexperienceService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Usr_workexperienceAction extends ActionSupport {
	private static final String Usr_workexperienceService = null;
	private Usr_workexperienceService usr_workexperienceService;
	private Usr_workexperience usr_workexperience;
	private Usr_projectexperienceService usr_projectexperienceService;
	private Usr_projectexperience usr_projectexperience; 
	
	private Cop_companyinfoService cop_companyinfoService;
	private Cop_companyinfo cop_companyinfo;
	
	public Usr_workexperienceService getUsr_workexperienceService() {
		return usr_workexperienceService;
	}

	public void setUsr_workexperienceService(
			Usr_workexperienceService usr_workexperienceService) {
		this.usr_workexperienceService = usr_workexperienceService;
	}
		
	public Usr_workexperience getUsr_workexperience() {
		return usr_workexperience;
	}

	public void setUsr_workexperience(Usr_workexperience usr_workexperience) {
		this.usr_workexperience = usr_workexperience;
	}
	
	public Usr_projectexperienceService getUsr_projectexperienceService() {
		return usr_projectexperienceService;
	}

	public void setUsr_projectexperienceService(
			Usr_projectexperienceService usr_projectexperienceService) {
		this.usr_projectexperienceService = usr_projectexperienceService;
	}

	public Usr_projectexperience getUsr_projectexperience() {
		return usr_projectexperience;
	}

	public void setUsr_projectexperience(Usr_projectexperience usr_projectexperience) {
		this.usr_projectexperience = usr_projectexperience;
	}

	//Set,get method of Cop_companyinfo
	public Cop_companyinfoService getCop_companyinfoService() {
		return cop_companyinfoService;
	}

	public void setCop_companyinfoService(
			Cop_companyinfoService cop_companyinfoService) {
		this.cop_companyinfoService = cop_companyinfoService;
	}

	public Cop_companyinfo getCop_companyinfo() {
		return cop_companyinfo;
	}

	public void setCop_companyinfo(Cop_companyinfo cop_companyinfo) {
		this.cop_companyinfo = cop_companyinfo;
	}

	public String addUsr_workexperience(){
	//	if(!(this.cop_companyinfo.getId().SIZE>0)){
		//System.out.println("add company-----");
			this.cop_companyinfo.setIsValidated(0);
			this.cop_companyinfoService.addCop_companyinfo(cop_companyinfo);
	//	}
		
		this.usr_workexperience.setCop_companyinfo(cop_companyinfo);
		this.usr_workexperienceService.addUsr_workexperience(usr_workexperience);
		
		this.usr_projectexperience.setUsr_workexperience(usr_workexperience);
		this.usr_projectexperienceService.addUsr_projectexperience(usr_projectexperience);
		return "addUsr_workexperience";
	}
	
	public String editUsr_workexperience(){
	//	if(!(this.cop_companyinfo.getId().SIZE>0)){
		//System.out.println("add company-----");
			this.cop_companyinfo.setIsValidated(0);
			this.cop_companyinfoService.editCop_companyinfo(cop_companyinfo);
	//	}
		
		this.usr_workexperience.setCop_companyinfo(cop_companyinfo);
		this.usr_workexperienceService.editUsr_workexperience(usr_workexperience);
		
		this.usr_projectexperience.setUsr_workexperience(usr_workexperience);
		this.usr_projectexperienceService.editUsr_projectexperience(usr_projectexperience);
		return "editUsr_workexperience";
	}
	
	public String findUsr_workexperienceByUserId(){
		//int user_id = Usr_workexperience.getUsr_user().getId();	
		int user_id = 1;	
		Usr_workexperience myUsr_workexperience = ((List<Usr_workexperience>)this.usr_workexperienceService.findUsr_workexperienceByUserId(user_id)).get(0);
		ActionContext.getContext().put("myUsr_workexperience", myUsr_workexperience);
		
		int work_exp_id = myUsr_workexperience.getId();	
		Usr_projectexperience myUsr_projectexperience = ((List<Usr_projectexperience>) this.usr_projectexperienceService.findUsr_projectexperienceByWorkexpId(work_exp_id)).get(0);
		ActionContext.getContext().put("myUsr_projectexperience", myUsr_projectexperience);
				
		return "findUsr_workexperienceByUserId";
	}
	
	public String findUsr_workexperienceById(){
		int id = usr_workexperience.getId();		
		Usr_workexperience myUsr_workexperience = ((List<Usr_workexperience>)this.usr_workexperienceService.findUsr_workexperienceById(id)).get(0);
		ActionContext.getContext().put("myUsr_workexperience", myUsr_workexperience);
		
		int work_exp_id = myUsr_workexperience.getId();	
		Usr_projectexperience myUsr_projectexperience = ((List<Usr_projectexperience>) this.usr_projectexperienceService.findUsr_projectexperienceByWorkexpId(work_exp_id)).get(0);
		ActionContext.getContext().put("myUsr_projectexperience", myUsr_projectexperience);
				
		return "findUsr_workexperienceById";
	}
}
